﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using NLog;

namespace Byond.Vst
{
	public partial class WinFormsHackEditor : UserControl
	{
		private readonly Logger _logger;
		private readonly WpfHost _wpfHost;
		private readonly IntPtr _parent;

		public WinFormsHackEditor(Logger logger, WpfHost wpfHost, IntPtr parent)
		{
			_logger = logger;
			_wpfHost = wpfHost;
			_parent = parent;

			InitializeComponent();
		}

		[DllImport("user32.dll")]
		public static extern IntPtr SetParent(IntPtr child, IntPtr newParent);

		private void btnShowByondWindow_Click(object sender, EventArgs e)
		{
			ShowWpfWindow();
		}

		public void Open()
		{
			SetParent(Handle, _parent);
			Show();
			ShowWpfWindow();
		}

		private void ShowWpfWindow()
		{
			_wpfHost.Show();
		}

		public void Close()
		{
			_wpfHost.Close();
		}
	}
}
